package cn.com.egova.web.interceptor;

import cn.com.egova.domain.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
import org.apache.struts2.ServletActionContext;

/**
 * Created by yuanchao on 2020/5/27.
 */
public class PrivilegeInterceptor extends MethodFilterInterceptor {
    @Override
    protected String doIntercept(ActionInvocation invocation) throws Exception {
        User existUser = (User) ServletActionContext.getRequest().getSession().getAttribute("existUser");
        if (existUser == null) {
            ActionSupport actionSupport = (ActionSupport) invocation.getAction();
            actionSupport.addActionError("您还没有登录，没有访问权限!");
            return ActionSupport.LOGIN;
        } else {
            return invocation.invoke();
        }
    }
}
